package tau.dimes.db;

import java.util.Map;
import java.util.TreeMap;

import tau.dimes.config.db.*;

public class DatabaseFactory
{
	private final static Map<String, Database> databases;

	static
	{
		databases = new TreeMap<String, Database>();
	}

	public static Database create(String name)
	{
		Database db = databases.get(name);

		if (db == null)
		{
			Server server = DatabaseConfiguration.getInstance().getServer(name);
			Driver driver = DatabaseConfiguration.getInstance().getDriver(server.getType());
			db = new Database(driver, server);
			databases.put(name, db);
		}
		
		return db;
	}
}
